package com.cskaoyan.java.object._3equals._1basic;

/**
 * equals方法标准格式的重写非常固定,可以使用alt + insert快捷键自动生成
 * 实际开发中,如无特殊需求,建议一律不要手写,自动生成
 *
 * @since 15:01
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo2 {
}

class A {
    int age;
    double num;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof A)) return false;

        A a = (A) o;

        if (age != a.age) return false;
        return Double.compare(a.num, num) == 0;
    }

/*@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        A a = (A) o;

        if (age != a.age) return false;
        return Double.compare(a.num, num) == 0;
    }*/

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = age;
        temp = Double.doubleToLongBits(num);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}